Xmpp.prototype.onStateChange = function (state){
}

function getRDFLiteral(ds, source, predicate){
	var target = ds.GetTarget(source, predicate, true).QueryInterface(CI.nsIRDFLiteral);
	return target.Value;
}

var jTL = null;
function fillField(id, rsrc)
{
	el = document.getElementById("xmpp.vcard." + id);
	if(!rsrc || !el)
		return;
	el.value = rsrc.QueryInterface(CI.nsIRDFLiteral).Value;
}

function fillCard()
{
	var rdf = CClasses["@mozilla.org/rdf/rdf-service;1"].getService(CI.nsIRDFService);
	var tags = new Array ("fn", "nickname", "url", "bday",  "tel", "title", "role", "desc", "adr", "n", "org");
	var subtags = new Array ();
	subtags ["adr"] = new Array("street", "ctry", "pcode", "locallity", "region", "extadd");
	subtags ["org"] = new Array("orgunit", "orgname");
	subtags ["n"] =	new Array ("family", "given", "middle");
	var root = rdf.GetResource(window.name); 
	for (i = 0; i < tags.length; i++)
	{
		var target = ds.GetTarget(root, rdf.GetResource(window.name+ ":" + tags[i]), true);
		if (target instanceof CI.nsIRDFLiteral)
		{
			fillField(tags[i], target);
		}
		if(target instanceof CI.nsIRDFResource)
		{
			var sub = subtags[tags[i]];
			for (var j = 0; j < sub.length; j++)
			{
				var name = sub[j];
				var lit  = ds.GetTarget(target, rdf.GetResource(window.name+":"+tags[i] + ":" + name), true)
				fillField(name, lit);
			}
		}
	}
}

function onLoad()
{
	ds  = jXmpp.getDataSource();
	fillCard();
	window.removeEventListener("load", onLoad, true);
}

var ds  = null;
window.addEventListener("load", onLoad, true);